using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class SpawnObject : MonoBehaviour {

	public string numHotkey = "";

	public GameObject objectPrefab;

	public float baseCost = 50;

	float Cost() {
		return baseCost * Mathf.Pow(1.25f, DefensiveBuilding.count);
	}

	public void DoSpawn() {
		GameManager gm = GameObject.FindObjectOfType<GameManager>();
		GameObject player = (GameObject)GameObject.Find("Player");

		/*Collider2D[] cols = Physics2D.OverlapCircleAll(player.transform.position, 1f, 1 << 8);
		foreach(Collider2D col in cols) {
			if(col.gameObject != player) {
				return;
			}
		}*/

		if(gm.score < (int)Cost ())
			return;

		gm.score -= (int)Cost ();


		if(player == null)
			return;

		Instantiate(objectPrefab, player.transform.position, player.transform.rotation );
	}

	void Update() {
		if(numHotkey != "" && Input.GetKeyDown(numHotkey)) {
			DoSpawn();
		}

		transform.Find ("Cost").GetComponent<Text>().text = "$" + Cost().ToString("f0");
	}
}
